export PATH="/home/ubuntu/.nvm/versions/node/v16.13.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

serverName=main-server

npm i

pm2 delete -s $serverName || :

workPath=/home/ubuntu/$serverName

if [ -d "$workPath" ]; then
  rm -rf $workPath
fi

mkdir $workPath

cp -r ./* $workPath

cd $workPath

DB_URL="mongodb://$dbUser:$dbPass@$dbUrl/collection?$dbParams" env="test" pm2 start ecosystem.config.js --update-env
